package com.zan.controller;

import com.zan.service.ProductCommentsService;
import com.zan.service.ProductService;
import com.zan.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/product")
@Api(value = "提供商品信息相关的接口", tags = "商品管理")
public class ProductController {

    @Autowired
    private ProductService productService;

    @Autowired
    private ProductCommentsService productCommentsService;

    @GetMapping("/detail-info/{pid}")
    @ApiOperation("商品基本信息查询接口")
    public ResultVo getProductBasicInfo(@PathVariable("pid") String pid) {
        return productService.getProductBasicInfo(pid);
    }

    @GetMapping("/detail-params/{pid}")
    @ApiOperation("商品参数信息查询接口")
    public ResultVo getProductParamsById(@PathVariable("pid") String pid) {
        return productService.getProductParamsById(pid);
    }

    @GetMapping("/detail-comments/{pid}")
    @ApiOperation("商品评论信息查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "pageNum", value = "当前页码", required = true),
            @ApiImplicitParam(dataType = "int", name = "limit", value = "每页显示条数", required = true)
    })
    public ResultVo getCommentsByProductId(@PathVariable("pid") String pid, int pageNum, int limit) {
        return productCommentsService.listCommentsByProductId(pid, pageNum, limit);
    }

    @GetMapping("/detail-comments-count/{pid}")
    @ApiOperation("商品评论数量信息查询接口")
    public ResultVo getCommentsCountByProductId(@PathVariable("pid") String productId) {
        return productCommentsService.getCommentsCountByProductId(productId);
    }

    @GetMapping("/listbycid/{cid}")
    @ApiOperation("根据类别查询商品信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "pageNum", value = "当前页码", required = true),
            @ApiImplicitParam(dataType = "int", name = "limit", value = "每页显示条数", required = true)
    })
    public ResultVo getCommentsByProductId(@PathVariable("cid") int cid, int pageNum, int limit) {
        return productService.getProductsByCategoryId(cid, pageNum, limit);
    }

    @GetMapping("/brand/{cid}")
    @ApiOperation("根据类别查询商品品牌信息接口")
    public ResultVo getBrandByCategoryId(@PathVariable("cid") int cid) {
        return productService.getProductBrandByCategoryId(cid);
    }

    @GetMapping("/listbykeyword")
    @ApiOperation("根据关键字搜索商品接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "keyword", value = "搜索关键字", required = true),
            @ApiImplicitParam(dataType = "int", name = "pageNum", value = "当前页码", required = true),
            @ApiImplicitParam(dataType = "int", name = "limit", value = "每页显示条数", required = true)
    })
    public ResultVo searchProducts(String keyword, int pageNum, int limit) {
        return productService.searchProduct(keyword, pageNum, limit);
    }

    @GetMapping("/brandByKw")
    @ApiOperation("根据关键字查询商品品牌信息接口")
    @ApiImplicitParam(dataType = "String", name = "keyword", value = "搜索关键字", required = true)
    public ResultVo getBrandByKeyWord(String keyword) {
        return productService.getProductBrandByKeyWord(keyword);
    }
}
